from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout
from conan.tools.files import get


class capicxxsomeipruntimeRecipe(ConanFile):
    name = "commonapi-someip"
    version = "3.2.3"  # 请根据实际最新版本进行更新
    license = "MPL-2.0"
    author = "Bayerische Motoren Werke Aktiengesellschaft (BMW AG)"
    url = "https://github.com/COVESA/capicxx-someip-runtime"
    description = ("The CommonAPI C++ SOME/IP Runtime is part of the CommonAPI C++ project aimed at providing a high-level C++ framework for service-oriented communication over IP networks. It specifically implements the Scalable service-Oriented MiddlewarE over IP (SOME/IP) protocol, facilitating the development of automotive applications.")
    topics = ("CommonAPI", "C++", "SOME/IP", "service-oriented", "automotive", "communication")
    # Binary configuration
    settings = "os", "compiler", "build_type", "arch"
    options = {"shared": [True, False], "fPIC": [True, False]}
    default_options = {"shared": False, "fPIC": True}
    #exports_sources = "lib_src/capicxx-core-runtime-3.2.3-r7/*"


    def source(self):
        # Please, be aware that using the head of the branch instead of an immutable tag
        # or commit is a bad practice and not allowed by Conan
        get(self, "https://github.com/COVESA/capicxx-someip-runtime/archive/refs/tags/3.2.3-r8.zip",
                  strip_root=True)

    def requirements(self):
        self.requires("boost/1.84.0")
        self.requires("vsomeip/3.4.10") 
        self.requires("CommonAPI/3.2.3")

    def config_options(self):
        if self.settings.os == "Windows":
            del self.options.fPIC

    def layout(self):
        cmake_layout(self)
#        self.folders.source = "lib_src/*"
        
    def generate(self):
        tc = CMakeToolchain(self)
        tc.generate()

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def package(self):
        cmake = CMake(self)
        cmake.install()

    def package_info(self):
        self.cpp_info.libs = ["CommonAPI-SomeIP"]